  Page({
    data: {
      actors:{
        '摄影师': [
          { name :"caozhihui",number:"123456"},
          { name : "daitaizong",number:"123456"},
        ],
        '化妆师': [
          { name : 'jiangwei',number:"123456" },
          { name : 'luoyingyouwei',number:"123456"}
        ],
        '设计师':[
          { name: "caozhihui",number:"123456" },
          { name :'luoyingyouwei',number:"123456" }
        ],
      },
      //商品发布数据
      productions:[],
      // 被选中的图片路径 数组
      chooseImgs: [],
      //显示和隐藏
      showView: false,
      // 文本域的内容
      textVal: ""
  
    },

    onLoad: function (options) {
      // 生命周期函数--监听页面加载
      showView: (options.showView == "true" ? true : false)
    },


    // 外网的图片的路径数组
    UpLoadImgs: [],
    handleTabsItemChange(e) {
      // 1 获取被点击的标题索引
      const { index } = e.detail;
      // 2 修改源数组
      let { tabs } = this.data;
      tabs.forEach((v, i) => i === index ? v.isActive = true : v.isActive = false);
      // 3 赋值到data中
      this.setData({
        tabs
      })
    },



    // 点击 “+” 选择图片
    handleChooseImg() {
      // 2 调用小程序内置的选择图片api
      wx.chooseImage({
        // 同时选中的图片的数量
        count: 9,
        // 图片的格式  原图  压缩
        sizeType: ['original', 'compressed'],
        // 图片的来源  相册  照相机
        sourceType: ['album', 'camera'],
        success: (result) => {
  
          this.setData({
            // 图片数组 进行拼接 
            chooseImgs: [...this.data.chooseImgs, ...result.tempFilePaths]
          })
        }
      });

  
    },
    // 点击 自定义图片组件
    handleRemoveImg(e) {
      // 2 获取被点击的组件的索引
      const { index } = e.currentTarget.dataset;
      // 3 获取data中的图片数组
      let { chooseImgs } = this.data;
      // 4 删除元素
      chooseImgs.splice(index, 1);
      this.setData({
        chooseImgs
      })
    },




    //点击切换
    onChangeShowState: function () {
      var that = this;
      that.setData({
        showView: (!that.data.showView)
      })
    },



    formReset: function () {
      console.log('form发生了reset事件')
    },
    
    formSubmit(e) {
      // console.log('form发生了submit事件，携带数据为：', e.detail.value.name);
      const { name1, number1, group}= e.detail.value
      // console.log(group)
      if (name1 == '' || number1 == '' || group == '') {
        wx.showModal({
          content: '输入信息不完整'
        })
      }
      else {
        this.data.actors[group].push({
          name: name1,
          number: number1
        })
        // console.log(this.data.actors);
        this.setData({
          actors: this.data.actors
        })
        this.formReset;
        wx.showToast({
          title: '添加成功',
          icon: 'success',
          duration: 2000
        })
      }
    
    },

    delete(e) {
      // console.log('发生删除事件，携带的数据是:',e.currentTarget.dataset)
      wx.showModal({
        content: '是否删除？？',
        success: (result) => {
          if(result.confirm){
            const key = e.currentTarget.dataset.key;
            const key1 = e.currentTarget.dataset.key1;
            delete this.data.actors[key].splice(key1,1);
            // console.log(this.data.actors)
            this.setData({
              actors: this.data.actors
            })
          }
        },
        fail: ()=>{},
        complete: ()=>{}
      });
      
    },

    uploader(e) {
      // console.log(e.detail);
      const { productionName, productionType, productionFee, productionplace }
        = e.detail.value;
      if (productionName == '' || productionType == '' || productionFee == '' || productionplace == '') {
        wx.showModal({
          content: '输入信息不完整'
        })
      }
      else {
        // console.log(productionName)
        const imgSrc = this.data.chooseImgs
        // console.log(imgSrc);
        this.data.productions.push({
          "productionName": productionName,
          "productionType": productionType,
          "productionFee": productionFee,
          "productionplace": productionplace,
          "imgSrc": imgSrc
        })
        // 调用自定义函数
        this.data.chooseImgs = [];
        this.data.actors["摄影师"] = [];
        this.data.actors["化妆师"] = [];
        this.data.actors["设计师"] = [];
        this.setData({
          productions: this.data.productions,
          chooseImgs: this.data.chooseImgs,
          actors: this.data.actors
        })

        wx.showToast({
          title: '上传成功！',
          icon: 'success',
          duration: 2000
        })
      }
    },

    uploaderReset(e) {
      // console.log("触发了重置事件");
      this.data.chooseImgs = [];
      this.data.actors["摄影师"] = [];
      this.data.actors["化妆师"] = [];
      this.data.actors["设计师"] = [];
      this.setData({
        productions: this.data.productions,
        chooseImgs: this.data.chooseImgs,
        actors: this.data.actors
      })
    },

  })